package com.csair.irp.job.file.parser.autogateway;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csair.irp.job.file.task.DispatchLogPO;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @Auther: liaolonglong
 * @Date: 2018/12/19 10:48
 * @Description:网关自动对接参数配置表
 */
@Service
public class AutodockingRelationshipService extends ServiceImpl<AutodockingRelationshipMapper, AutodockingRelationshipPO> {

    /**
     * 根据文件基础信息ID获取商户号
     *
     * @param fileBaseinfoId
     * @return
     */
    public String getBusinessNumberByFileBaseinfoId(Long fileBaseinfoId) {
        return baseMapper.getBusinessNumberByFileBaseinfoId(fileBaseinfoId);
    }

    /**
     * 根据商户号查数据
     *
     * @return
     */
    public List<AutodockingRelationshipPO> getGatewayBybusinessNumber(String businessNumber) {
        QueryWrapper<AutodockingRelationshipPO> wrapper = new QueryWrapper<>();
        wrapper.eq("business_number", businessNumber);
        return list(wrapper);
    }

    /**
     * 根据网关代码查数据
     *
     * @return
     */
    public List<AutodockingRelationshipPO> getGatewayByGatewaycode(String gateway_code) {
        QueryWrapper<AutodockingRelationshipPO> wrapper = new QueryWrapper<>();
        wrapper.eq("gateway_code", gateway_code);
        return list(wrapper);
    }


    /**
     * @param gatewayCode
     * @return
     * @Description: 查找等于gatewayCode的自动对接网关记录集合
     * @author zou_cailue
     * @date 2018年2月28日 上午10:23:06
     */
    public List<AutodockingRelationshipPO> getByGatewayCode(String gatewayCode) {
        QueryWrapper<AutodockingRelationshipPO> wrapper = new QueryWrapper<>();
        Object[] autoDocking = {"1", "3"};
        wrapper.eq("gateway_code", gatewayCode);
        wrapper.in("auto_docking", autoDocking);
        return list(wrapper);
    }

    /**
     * 根据商户号查询出数据
     *
     * @param businessNumber
     * @return 网关代码集合
     */
    public String getGatewayCodebyBusinessNumber(String businessNumber) {
        return baseMapper.getGatewayCodebyBusinessNumber(businessNumber);
    }

    /**
     * 根据商户号更新状态
     *  @param etl_state
     * @param business_number
     * @param totalAmount
     * @param resourceIds 文件ID
     */
    public void updateAutoGatewayState(int etl_state, String business_number, String transaction_date, BigDecimal totalAmount, double dispatchTime, String resourceIds) {
        baseMapper.updateAutoGatewayState(etl_state, business_number, transaction_date, totalAmount, dispatchTime,resourceIds);
    }

    /**
     * 获取某个网关的统计交易金额
     *
     * @param gatewayCode
     * @param transactionDate
     * @param etlState
     * @return
     */
    public List<DispatchLogPO> getAutoGatewayDispatchLog(String gatewayCode, Date transactionDate, int etlState) {
        return baseMapper.getAutoGatewayDispatchLog(gatewayCode, transactionDate, etlState);
    }

    /**
     * 找到同一个网关多个商户号的解析情况
     *
     * @param gateway_code
     * @return
     */
    public List<String> getGatewaySuccessInfoByGatewaycode(String gateway_code, Date dispatchDate) {
        return baseMapper.getGatewaySuccessInfoByGatewaycode(gateway_code, dispatchDate);
    }

    /**
     * 获取与该商户号相同网关的所有商户号
     * @param businessNumber
     * @return
     */
    public List<String> getBusinessNumbersByGatewayCode(String businessNumber) {
        return baseMapper.getBusinessNumbersByGatewayCode(businessNumber);
    }

}
